/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = frhash2.h                                          */
/*  NOTE      =                                                    */
/*  DATE      = 2014/11/12 by yaohl                                */
/*******************************************************************/

#ifndef __FRHASH2_H_
#define __FRHASH2_H_

#include "frlist.h"

typedef struct __st_hash {
    unsigned long   ul_hash_size;        /* 数组长度 */
    Frlist_header  *p_list_array;

} Frhash_header;

unsigned long frhash_key(unsigned char *p_data, unsigned int ui_len);

int frhash2_create(Frhash_header *p_hash_hdr, unsigned long ul_hash_size);
Frhash_header *frhash2_create2(unsigned long ul_hash_size);
void frhash2_free(Frhash_header *p_hash_hdr, list_node_free pf_free);
void frhash2_free2(Frhash_header *p_hash_hdr, list_node_free pf_free);

//i_loop循环用变量,p_hash_hdr hash表指针, p_lst_hdr_tmp链表用临时变量
#define FRHASH_LOOP(i_loop,p_hash_hdr, p_lst_hdr_tmp)  \
        for(i_loop=0; i_loop < (p_hash_hdr)->ul_hash_size && (p_lst_hdr_tmp = &((p_hash_hdr)->p_list_array[i_loop]) ); i_loop++)

int frhash2_addStr(Frhash_header *p_hash_hdr, char *p_key, unsigned int ui_key_len, Frlist_node *p_st_node_add);
Frlist_node *frhash2_getStr(Frhash_header *p_hash_hdr, char *p_key, unsigned int ui_key_len);
int frhash2_delStr(Frhash_header *p_hash_hdr, char *p_key, unsigned int ui_key_len, list_node_free pf_free);

int frhash2_addLong(Frhash_header *p_hash_hdr, long l_key, Frlist_node *p_st_node_add);
Frlist_node *frhash2_getLong(Frhash_header *p_hash_hdr, long l_key);
int frhash2_delLong(Frhash_header *p_hash_hdr, long l_key, list_node_free pf_free);

Frlist_node *frhash2_find(Frhash_header *p_hash_hdr, void *p_data, list_node_find pf_find);
Frlist_node *frhash2_find_strKey(Frhash_header *p_hash_hdr, char *p_key, unsigned int ui_key_len
                               , void *p_data, list_node_find pf_find);
int frhash2_del(Frhash_header *p_hash_hdr, Frlist_node *p_st_node_del, list_node_free pf_free);
void frhash2_show(Frhash_header *p_hash_hdr, char *p_outbuff, unsigned int ui_buff_size, list_node_show pf_show);
void frhash2_show_all(Frhash_header *p_hash_hdr, char **pp_outbuff, list_node_show_all pf_show);
void frhash2_show_all2(Frhash_header *p_hash_hdr, char **pp_outbuff, list_node_show pf_show);
void frhash2_run(Frhash_header *p_hash_hdr, void *p_data, list_node_run pf_run);

//释放节点的data数据
#define frhash2_node_data_free(x) frlist_node_data_free(x)

#endif
